package com.dstz.sys.service.impl;

import java.io.InputStream;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import com.dstz.base.core.util.BeanCopierUtils;
import com.dstz.sys.api.model.dto.SysFileDTO;
import com.dstz.sys.api.service.SysFileService;
import com.dstz.sys.core.manager.SysFileManager;
import com.dstz.sys.core.model.SysFile;

import cn.hutool.core.util.ArrayUtil;
@Service
public class SysFileServiceImpl implements SysFileService {
	@Autowired
	private SysFileManager sysFileMananger;
	
	
	@Override
	public SysFileDTO upload(InputStream is, String fileName) {
		SysFile file = sysFileMananger.upload(is, fileName);
		return BeanCopierUtils.transformBean(file, SysFileDTO.class);
	}

	@Override
	public InputStream download(String fileId) {
		return sysFileMananger.download(fileId);
	}

	@Override
	public void delete(String ... fileId) {
		if(ArrayUtil.isEmpty(fileId))return;
		
		for(String id : fileId) {
			sysFileMananger.delete(id);
		}
	}

}
